package com.hfy.admin.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.powerjob.official.processors.impl.sql.AbstractSqlProcessor;
import tech.powerjob.official.processors.impl.sql.DynamicDatasourceSqlProcessor;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.WorkflowContext;

import java.sql.*;

/**
 * @ author 韩
 * time: 2025/3/6 18:12
 */

@Configuration
public class ProcessorConfig {


    @Bean
    public DynamicDatasourceSqlProcessor simpleSpringSqlProcessor() {
        DynamicDatasourceSqlProcessor dynamicDatasourceSqlProcessor = new DynamicDatasourceSqlProcessor();
        // 排除掉包含 drop 的 SQL

        dynamicDatasourceSqlProcessor.setSqlParser((sql, taskContext) -> {
            WorkflowContext workflowContext = taskContext.getWorkflowContext();
            int index = 1;
            while (workflowContext.getAppendedContextData().get("sql" + index) != null) {
                index++;
            }
            workflowContext.appendData2WfContext("sql" + index, sql);
            return sql;
        });

        return dynamicDatasourceSqlProcessor;
    }

// 定义切入点，匹配 AbstractSqlProcessor 类的 executeSql 方法

}
